package com.example.newstest.comment;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.newstest.R;

import com.example.newstest.comment.bean.MyCommentFragment;
import com.example.newstest.databinding.FragmentCommentBinding;
import com.example.newstest.until.CommentPagerFragmentAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class CommentFragment extends Fragment {
    private FragmentCommentBinding binding;
    private CommentPagerFragmentAdapter adapter;

    public CommentFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return DataBindingUtil.inflate(inflater,R.layout.fragment_comment, container, false).getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = DataBindingUtil.getBinding(view);
        String[] title = new String[]{"日热门评论","周热门评论","我的评论"};
        List<Fragment> fragments = new ArrayList<>();
        DayCommentFragment dayCommentFragment = new DayCommentFragment().newInstance(1);
        DayCommentFragment dayCommentFragment2 = new DayCommentFragment().newInstance(7);
        fragments.add(dayCommentFragment);
        fragments.add(dayCommentFragment2);
        fragments.add(new MyCommentFragment());
        adapter = new CommentPagerFragmentAdapter(getChildFragmentManager(),fragments,title);
        binding.viewpager.setAdapter(adapter);
        binding.tablayout.setupWithViewPager(binding.viewpager);
        binding.viewpager.setOffscreenPageLimit(3);
    }
}
